package javaDemo14.JDBC;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class DruidDemo {
    public static void main(String[] args) throws Exception {

        Properties prop = new Properties();

        prop.load(new FileInputStream("C:\\Users\\zx\\IdeaProjects\\JAVAbase\\src\\javaDemo14\\JDBC\\druid.properties"));

        DataSource ds = DruidDataSourceFactory.createDataSource(prop);
        
        Connection conn = null;
        
        for (int i = 1; i <= 8; i++) {
            conn = ds.getConnection();
            System.out.println(conn);
        }

        String sql = "SELECT * FROM USER";

        PreparedStatement prep = conn.prepareStatement(sql);

        ResultSet res = prep.executeQuery(sql);

        while(res.next()){
            int id = res.getInt("id");
            String name = res.getString("name");
            int age = res.getInt("age");
            int status = res.getInt("status");
            String gender = res.getString("gender");

            System.out.println("id=" + id + ",name=" + name + ",age=" + age + ",status=" + status + ",gender=" + gender);
        }

        prep.close();
        conn.close();



    }
}
